package com.qianfeng.xinyihezi.xinyihezi.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.qianfeng.xinyihezi.xinyihezi.R;
import com.qianfeng.xinyihezi.xinyihezi.model.GoodBean;

import java.util.List;

/**
 * 作者：王加威 on 2016/11/14 19:38
 */

public class MyGoodBeanAdapter extends BaseAdapter{
    private Context mContext;
    private List<GoodBean.DataBean> mGoodBeen;

    public MyGoodBeanAdapter(Context context, List<GoodBean.DataBean> goodBeen) {
        mContext = context;
        mGoodBeen = goodBeen;
    }

    @Override
    public int getCount() {
        return mGoodBeen==null?0:mGoodBeen.size();
    }

    @Override
    public Object getItem(int position) {
        return mGoodBeen.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        convertView=null;
        if (convertView == null) {
            convertView= LayoutInflater.from(mContext).inflate(R.layout.zhuiti_item,null);
            viewHolder=new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        }else {
            viewHolder= (ViewHolder) convertView.getTag();
        }
        Glide.with(mContext).load(mGoodBeen.get(position).image_url).into(viewHolder.mImageView);
        viewHolder.mTextView1.setText(mGoodBeen.get(position).short_name);
        viewHolder.mTextView2.setText(mGoodBeen.get(position).price+"");
        viewHolder.mTextView3.setText(mGoodBeen.get(position).like_count);

        return convertView;
    }
    private static class ViewHolder{
        private ImageView mImageView;
        private TextView mTextView1,mTextView2,mTextView3;

        public ViewHolder(View itemView) {

            mImageView= (ImageView) itemView.findViewById(R.id.zhuti_item_iv);
            mTextView1= (TextView) itemView.findViewById(R.id.zhuti_item_title);
            mTextView2= (TextView) itemView.findViewById(R.id.zhuti_item_price);
            mTextView3= (TextView) itemView.findViewById(R.id.zhuti_item_liike);
        }
    }
}
